#include <iostream>
#include <iomanip>

using namespace std;
//
class Myclass
{
private:
    Myclass() // 私有构造函数，之能在类内部调用它，不能再外面调用他
    {
    }

public:
    int n;
    static Myclass *p;
    static Myclass *getObject()
    {
        if (p == NULL) // 还没有创建对象
        {
            Myclass *object = new Myclass; // 类成员可以调用私有成员
            p = object;
            return object;
        }
        else // 创建过对象
        {
            return p;
        }
    }
};

Myclass *Myclass::p = NULL; // 定义一个全局指针

int main(int argc, char const *argv[])
{
    Myclass *object = Myclass::getObject();
    object->n = 100;
    cout << object->n << "  " << object << endl;

    Myclass *object2 = Myclass::getObject();
    cout << object2->n << "  " << object2 << endl;

    Myclass *object3 = Myclass::getObject();
    cout << object3->n << "  " << object3 << endl;

    return 0;
}
